﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using DevExpress.XtraPrinting.Native;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using Lamex.Interface;
using Lamex.Library;

namespace Lamex.mDashboard.UI
{
    public partial class frmDB_ProductInWareHouseStatistics : frmBaseChild
    {
        List<string> addedFunctionList = new List<string>();
        string str = "";
        string str1 = "";
        string str2 = "";
        public frmDB_ProductInWareHouseStatistics()
        {
            InitializeComponent();
            this.Load += new EventHandler(frmDB_ProductInWareHouseStatistics_load);
            cmbStartTime.EditValue = DateTime.Now;
            cmbEndTime.EditValue = DateTime.Now;

            //trListDate.BeforeCheckNode += new DevExpress.XtraTreeList.CheckNodeEventHandler(treeList1_BeforeCheckNode);
            //trListDate.AfterCheckNode += new DevExpress.XtraTreeList.NodeEventHandler(treeList1_AfterCheckNode);


        }
        bool ifMultipleChoice = true;
        private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e)
        {
            if (!this.ifMultipleChoice)
            {
                //选择前取消前面已经选择的，实现单选功能
                //List<DevExpress.XtraTreeList.Nodes.TreeListNode> treeListNodes = trListDate.GetAllCheckedNodes();
                //foreach (DevExpress.XtraTreeList.Nodes.TreeListNode node in treeListNodes)
                //{
                //    node.Checked = false;
                //}
            }
            e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);

        }
       
        private void treeList1_AfterCheckNode(object sender, NodeEventArgs e)
        {
            if (!this.ifMultipleChoice)
            {
                return;
            }
            if (e.Node == null)
            {
                return;
            }
            if (e.Node.CheckState == CheckState.Indeterminate)
            {
                e.Node.CheckState = CheckState.Checked;
            }
            if (e.Node.CheckState == CheckState.Checked)
            {
                if (e.Node.HasChildren)
                {
                    this.CheckNode(e.Node);
                }
                this.ValidParentIsChecked(e.Node);
            }
            else if (e.Node.CheckState == CheckState.Unchecked)
            {
                if (e.Node.HasChildren)
                {
                    this.SetCheckedChildNodes(e.Node, CheckState.Unchecked);
                }
                //从根节点往下 查询 是否有打钩的子节点，如果有那么 父节点的 半选状态不变 否则变为 不选择状态  
                //this.ValidParentNodeIsCanleSel(e.Node);
                SetCheckedParentNodes(e.Node, e.Node.CheckState);
            }
        }
        private void frmDB_ProductInWareHouseStatistics_load(object sender,EventArgs e)
        {
            try { base.InitButtons(); } catch { }//初始化标准功能，因要应用于RibbonForm，所以加入异常处理
            initLoad();
        }

        private void initLoad()
        {
            string sql = @"
                        select distinct( convert(nvarchar(4),Scn_Date)) as ID,'-1' as PID into #t from Transfer_Scanning_record

                        select ID,PID into #t1 from (
                        select distinct(convert(nvarchar(7),Scn_Date)) as ID,  convert(nvarchar, (YEAR(Scn_Date))) as PID from Transfer_Scanning_record  ) a  group by PID,ID order by  pid,ID

                        select ID,PID into #t2 from (
                        select distinct(convert(nvarchar(10),Scn_Date)) as ID, (convert(nvarchar(7),Scn_Date)) as PID from Transfer_Scanning_record  ) a  group by PID,ID order by pid,id

						--select ID,PID from #t1 order by pid,id
						select * from (
                        select ID,PID from #t 
                        union all
                        select ID,PID from #t1
                        union all
                        select ID,PID from #t2) m order by PID,ID
                        drop table #t
                        drop table #t1
                        drop table #t2

                       
	                   select distinct(PROCESS_NAME) [工作中心],PROCESS_CODE as [工作中心代码] from IE_WorkCenter_Definition order by PROCESS_CODE desc

                       select distinct( PROD_LINE) from Transfer_Package_List

                        ";


            DataSet ds = Lamex.Base.BaseBuildSql.GetDataSetBySql(sql);
            DataTable dt = ds.Tables[0];
            
            foreach(DataRow dr in ds.Tables[2].Rows)
            {
                cmbProductLine.Properties.Items.Add(dr["PROD_LINE"].ToString());
            }
            //cmbProductLine.Properties.Items.Add("M");
            //cmbProductLine.Properties.Items.Add("D");
            //cmbProductLine.Properties.Items.Add("P");
            //cmbProductLine.Properties.Items.Add("S");
           
           cmbFactoryCenter.Properties.DisplayMember = "工作中心";
            cmbFactoryCenter.Properties.ValueMember = "工作中心代码";
            cmbFactoryCenter.Properties.DataSource = ds.Tables[1];


        }
        private void LoadDate(string id,TreeListNode node,DataTable dt)
        {
            DataRow[] drows = dt.Select("PID='"+ id + "'");
            foreach(DataRow dr in drows)
            {
                TreeListNode topnode = node.Nodes.Add(new object[] { dr["ID"] });
                LoadDate(dr["ID"].ToString(), topnode, dt);
            }

        }
        public override void DoView(IButtonInfo sender)
        {
            str = "";
            str1 = "";
            str2 = "";
            //TreeListNodes nodes = trListDate.Nodes;
            //int iYear = 0;
            //int iMont = 0;
            //int iDay = 0;
            if (!string.IsNullOrEmpty(cmbProductLine.Text))
            {
                
                str += " and PROD_LINE='"+ cmbProductLine.Text + "'";
            }
            else
            {
                XtraMessageBox.Show("分厂不能为空！");
                return;
            }

            if (!string.IsNullOrEmpty(cmbFactoryCenter.Text))
            {
                str1 += " and k.PROCESS_NAME='" + cmbFactoryCenter.Text + "'";
            }
            else
            {
                XtraMessageBox.Show("工作中心不能为空！");
                return;
            }
            if (!string.IsNullOrEmpty(cmbStartTime.Text))
            {
                str1 += " and Scn_Date>='" + cmbStartTime.Text + "'";
            }
            else
            {
                XtraMessageBox.Show("开始时间不能为空！");
                return;
            }
            if (!string.IsNullOrEmpty(cmbEndTime.Text))
            {
                str1 += " and Scn_Date<='" + cmbEndTime.Text + "'";
            }
            else
            {
                XtraMessageBox.Show("结束时间不能为空！");
                return;
            }

            #region""

            //foreach (TreeListNode sub in nodes) 
            //{
            //    string Years = sub.GetDisplayText("ID");
            //    if (Years != "日期")
            //    {
            //        if(sub.Checked==true)
            //            iYear++;
            //    }
            //}
            //if(iYear>1)
            //{
            //    XtraMessageBox.Show("年份不能多选！");
            //    return;
            //}
            //foreach (TreeListNode sub in nodes)
            //{
            //    foreach (TreeListNode subNodes in sub.Nodes)
            //    {
            //        if (subNodes.Checked == true)
            //            iMont++;
            //    }
            //}
            //if (iMont > 1)
            //{
            //    XtraMessageBox.Show("月份不能多选！");
            //    return;
            //}
            //foreach (TreeListNode sub in nodes)
            //{
            //    foreach (TreeListNode subNodes in sub.Nodes)
            //    {
            //        foreach (TreeListNode subday in subNodes.Nodes)
            //        {
            //            iDay++;
            //        }
            //    }
            //}
            //if(iDay==0)
            //{
            //    XtraMessageBox.Show("没有选择天数！");
            //    return;
            //}
            //if(iDay==1)
            //{
            //    foreach (TreeListNode sub in nodes)
            //    {
            //        foreach (TreeListNode subNodes in sub.Nodes)
            //        {
            //            foreach (TreeListNode subday in subNodes.Nodes)
            //            {
            //                str2 += " convert(nvarchar(7), Scn_Date)=CONVERT(nvarchar(7),'" + subday.GetDisplayText("ID") + "')";
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    int m = 0;
            //    foreach (TreeListNode sub in nodes)
            //    {
            //        foreach (TreeListNode subNodes in sub.Nodes)
            //        {
            //            foreach (TreeListNode subday in subNodes.Nodes)
            //            {
            //                if(subday.Checked==true)
            //                {
            //                    if (m == 0)
            //                    {
            //                        str2 += "  convert(nvarchar(7), Scn_Date)=CONVERT(nvarchar(7),'" + subday.GetDisplayText("ID") + "')";
            //                        m++;
            //                    }

            //                    else
            //                        str2 += " or convert(nvarchar(7), Scn_Date)=CONVERT(nvarchar(7),'" + subday.GetDisplayText("ID") + "')";
            //                }

            //            }
            //        }
            //    }
            //}

            //TreeListNodes subNodes = trListDate.Nodes;



            //foreach (TreeListNode subNode in this.trListDate.Nodes)
            //{
            //    string Years = subNode.GetDisplayText("ID");
            //    if (Years != "日期")
            //    {
            //        //if (subNode.CheckState == CheckState.Checked)
            //        //{
            //        //    if(m==0)
            //        //    {
            //        //        str2 += " convert(nvarchar(4), Scn_Date)=CONVERT(nvarchar(4),'" + subNode.GetDisplayText("ID") + "') ";
            //        //        GetFunctionChanges(subNode);
            //        //        m++;
            //        //    }

            //        //}
            //        //else if (subNode.CheckState == CheckState.Indeterminate)
            //        //{
            //        //    GetFunctionChanges(subNode);
            //        //}
            //        //else if (subNode.CheckState == CheckState.Unchecked)
            //        //{
            //        //    str2 += " ";
            //        //}
            //        GetFunctionChanges(subNode);
            //    }
            //}
            #endregion
            //str2 = " and ( "+ str2;
            //str2 += " )";
            string sql = @"

select convert(nvarchar(10), y.Scn_Date, 120) Scn_Date,CONVERT(decimal(10,1),sum(InsideQty))  InsideQty from (
select 

    a.ProdOrder,a.Scn_ID, a.Scn_Date,a.Scn_Time,a.Kaban,a.InsideQty,a.Scale_weight,a.Cancel_Flag,a.Material_No,a.PROD_LINE,b.ROUTING_CODE

from 

    (select m.ProdOrder,m.Scn_ID, m.Scn_Date,m.Scn_Time,m.Kaban,m.InsideQty,m.Scale_weight,m.Cancel_Flag,m.Material_No,m.PROD_LINE,ROUTING_CODE=convert(xml,'<root><v>'+replace(ROUTING_CODE,'_','</v><v>')+'</v></root>')  from (
select a.ProdOrder,a.Scn_ID, a.Scn_Date,a.Scn_Time,a.Kaban,a.InsideQty,a.Scale_weight,a.Cancel_Flag,b.Material_No,b.PROD_LINE,d.ROUTING_CODE from Transfer_Scanning_record a
 join Transfer_Package_List b on a.ProdOrder=b.Package_Mo
 join IE_Part_Routing c on b.Material_No=c.PART_NO
 join  IE_Routing_Combination d on d.GROUP_CODE=c.GROUP_CODE
where ISNULL(a.Cancel_Flag,'')='' " + str+ str2 + @") m
	
	)a 

outer apply

    (select ROUTING_CODE=C.v.value('.','nvarchar(100)') from a.ROUTING_CODE.nodes('/root/v')C(v))b) y
	join IE_WorkCenter_Definition k on k.PROCESS_CODE=y.ROUTING_CODE 
	where 1=1 "+ str1 + @"
	group by Scn_Date order by Scn_Date



select CONVERT(varchar(2), CONVERT(varchar(2),Scn_Time, 108)) Scn_Time, sum(InsideQty) InsideQty from (
select 

    a.ProdOrder,a.Scn_ID, a.Scn_Date,a.Scn_Time,a.Kaban,a.InsideQty,a.Scale_weight,a.Cancel_Flag,a.Material_No,a.PROD_LINE,b.ROUTING_CODE

from 

    (select m.ProdOrder,m.Scn_ID, m.Scn_Date,m.Scn_Time,m.Kaban,m.InsideQty,m.Scale_weight,m.Cancel_Flag,m.Material_No,m.PROD_LINE,ROUTING_CODE=convert(xml,'<root><v>'+replace(ROUTING_CODE,'_','</v><v>')+'</v></root>')  from (
select a.ProdOrder,a.Scn_ID, a.Scn_Date,a.Scn_Time,a.Kaban,a.InsideQty,a.Scale_weight,a.Cancel_Flag,b.Material_No,b.PROD_LINE,d.ROUTING_CODE from Transfer_Scanning_record a
 join Transfer_Package_List b on a.ProdOrder=b.Package_Mo
 join IE_Part_Routing c on b.Material_No=c.PART_NO
 join  IE_Routing_Combination d on d.GROUP_CODE=c.GROUP_CODE
where ISNULL(a.Cancel_Flag,'')='' " + str + str2 + @") m
	
	)a 

outer apply

    (select ROUTING_CODE=C.v.value('.','nvarchar(100)') from a.ROUTING_CODE.nodes('/root/v')C(v))b) y
	join IE_WorkCenter_Definition k on k.PROCESS_CODE=y.ROUTING_CODE 
	where 1=1 " + str1 + @"
	group by CONVERT(varchar(2), CONVERT(varchar(2),Scn_Time, 108))
	order by Scn_Time
";
            chart_Day.Series.Clear();
            chart_Hour.Series.Clear();
            DataSet ds = Lamex.Base.BaseBuildSql.GetDataSetBySql(sql);
            gridMain.DataSource = ds.Tables[0];


            Series seriesAuto = new Series("天", ViewType.Bar);
            seriesAuto.DataSource = ds.Tables[0];
            seriesAuto.ArgumentDataMember = "Scn_Date";
            seriesAuto.ValueDataMembers.AddRange(new string[] { "InsideQty" });
            seriesAuto.Label.Font = new System.Drawing.Font("Tahoma", 8F);
            seriesAuto.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            SideBySideBarSeriesLabel label = (SideBySideBarSeriesLabel)seriesAuto.Label;
            label.Position = BarSeriesLabelPosition.Top;

            //seriesAuto.PointOptions.PointView = PointView.Argument;
            //seriesAuto.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;

            chart_Day.Series.Add(seriesAuto);
            //series title positive setting
            //Legend Legends = (Legend)chart_Day.Legend;
            //Legends.Visibility = DevExpress.Utils.DefaultBoolean.True;
            //Legends.AlignmentVertical = LegendAlignmentVertical.TopOutside;
            //Legends.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
            //Legends.Direction = LegendDirection.LeftToRight;
            //Legends.TextVisible = true;


            Series seriesAuto2 = new Series("小时", ViewType.Bar);
            seriesAuto2.DataSource = ds.Tables[1];

            //foreach (DataRow drow in ds.Tables[1].Rows)
            //{
            //    SeriesPoint p = new SeriesPoint();

            //    double[] d = new double[] { double.Parse( drow ["InsideQty"].ToString())};
            //    p.Values = d;

            //    p.Argument = drow["Scn_Time"].ToString();
            //    p.Color = Color.Gray;
            //    seriesAuto.Points.Add(p);
            //}




            seriesAuto2.ArgumentDataMember = "Scn_Time";
            seriesAuto2.ValueDataMembers.AddRange(new string[] { "InsideQty" });
            
            seriesAuto2.Label.Font = new System.Drawing.Font("Tahoma", 8F);
            //seriesAuto2.PointOptions.PointView = PointView.Argument;
            //seriesAuto2.PointOptions.ValueNumericOptions.Format = NumericFormat.Number;

            //BarSeriesLabel point = (BarSeriesLabel)seriesAuto2.Label;
            //point.Position = BarSeriesLabelPosition.TopInside;

            seriesAuto2.LabelsVisibility = DevExpress.Utils.DefaultBoolean.True;
            SideBySideBarSeriesLabel label2 = (SideBySideBarSeriesLabel)seriesAuto2.Label;
            label2.Position = BarSeriesLabelPosition.Top;
            //seriesAuto2.ArgumentScaleType = ScaleType.Auto;
            chart_Hour.Series.Add(seriesAuto2);

            //series title positive setting
            //Legend Legends2 = (Legend)chart_Hour.Legend;
            ////Legends2.AxisX.QualitativeScaleOptions.AutoGrid = false;
            //Legends2.Visibility = DevExpress.Utils.DefaultBoolean.True;
            //Legends2.AlignmentVertical = LegendAlignmentVertical.TopOutside;
            //Legends2.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
            //Legends2.Direction = LegendDirection.LeftToRight;
            //Legends2.TextVisible = true;

            //DevExpress.XtraCharts.XYDiagram diagram = ((DevExpress.XtraCharts.XYDiagram)chart_Hour.Diagram);

            //diagram.AxisX.QualitativeScaleOptions.AutoGrid = false;
            //diagram.AxisX.Tickmarks.MinorVisible = false;
            //diagram.AxisX.Label.ResolveOverlappingOptions.AllowHide = false;
            //diagram.AxisX.GridLines.Visible = false;
            //AxisBase axis = diagram.AxisX;
            //axis.DateTimeOptions.FormatString = "HH";




            base.DoView(sender);
        }
        private void GetFunctionChanges(TreeListNode node)
        {
            
             foreach (TreeListNode subNode in node.Nodes)
            {

                if (subNode.CheckState == CheckState.Checked)
                {
                    str2 += " or convert(nvarchar(7), Scn_Date)=CONVERT(nvarchar(7),'" + subNode.GetDisplayText("ID") + "')";
                    GetFunctionChanges(subNode);
                }
                else if (subNode.CheckState == CheckState.Indeterminate)
                {
                    GetFunctionChanges(subNode);
                }
                else if (subNode.CheckState == CheckState.Unchecked)
                {
                    str2 += " ";
                }
                //string month = subNode.GetDisplayText("ID");
                GetDayFunctionChanges(subNode);
            }
        }
        private void GetDayFunctionChanges(TreeListNode node)
        {
            int month = 0;

            foreach (TreeListNode subNode in node.Nodes)
            {
                if (subNode.Checked == true) month++;
            }

            foreach (TreeListNode subNode in node.Nodes)
            {
                if (subNode.Checked == true)
                    str2 += " or convert(nvarchar(10), Scn_Date)=CONVERT(nvarchar(10),'" + subNode.GetDisplayText("ID") + "')";
                else
                    str2 += "";
            }
        }
        private void pl_Main_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pl_Main_Resize(object sender, EventArgs e)
        {
            int iHeight = pl_Main.Height;
            int iMid = iHeight / 2;
            pl_chart1.Height = iMid;
            pl_Chart2.Dock = DockStyle.Fill;

        }

        private void cmbFactoryCenter_TextChanged(object sender, EventArgs e)
        {
            string sql = @"select distinct(PROCESS_CODE) from IE_WorkCenter_Definition where PROCESS_NAME='"+ cmbFactoryCenter.Text+ "' ";
            DataTable dt = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);
            if(dt.Rows.Count!=0)
            {
                cmbFactoryCenter.Text = dt.Rows[0]["PROCESS_CODE"].ToString();
            }
            else
                cmbFactoryCenter.Text = "";
        }



        #region 树形 节点操作集合
        /// <summary>  
        /// 选择某个节点及其子节点  
        /// </summary>  
        /// <param name="node"></param>  
        private void CheckNode(DevExpress.XtraTreeList.Nodes.TreeListNode node)
        {
            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode cnode in node.Nodes)
            {
                if (cnode != null)
                {
                    cnode.CheckState = CheckState.Checked;
                }
                if (cnode.HasChildren)
                {
                    CheckNode(cnode);
                }
            }
        }

        /// <summary>  
        /// 勾选子节点后，修改父节点的状态  
        /// </summary>  
        /// <param name="node"></param>  
        private void ValidParentIsChecked(DevExpress.XtraTreeList.Nodes.TreeListNode node)
        {
            if (node.ParentNode != null)
            {
                //父节点未被选中  
                if (node.ParentNode.CheckState == CheckState.Unchecked)
                {
                    //该节点有子节点 并且  该节点与子节点均被选中  
                    if (node.HasChildren && ValidIsCheckAllChildNode(node.ParentNode))
                    {
                        node.ParentNode.CheckState = CheckState.Checked;
                    }
                    //该节点没有子节点 并且 其父节点下的子节点均被选中  
                    else if ((!node.HasChildren) && ValidIsCheckAllChildNode(node.ParentNode))
                    {
                        node.ParentNode.CheckState = CheckState.Checked;
                    }
                    else
                    {
                        node.ParentNode.CheckState = CheckState.Indeterminate;
                    }
                }
                else if (node.ParentNode.CheckState == CheckState.Indeterminate)
                {
                    //该节点有子节点并且 子节点均未被选中时，修改其状态   
                    if (node.HasChildren && (!this.ValidIsHasCheckChildNode(node)))
                    {
                        node.ParentNode.CheckState = CheckState.Unchecked;
                    }
                    // 该节点的父节点下所有节点均被选中 ValidIsCheckAllChildNode  
                    else if (ValidIsCheckAllChildNode(node.ParentNode))
                    {
                        node.ParentNode.CheckState = CheckState.Checked;
                    }
                }
                this.ValidParentIsChecked(node.ParentNode);
            }
        }

        /// <summary>  
        /// 从该节点往下 查询 是否有打钩的子节点，如果有那么 父节点的 半选、选中状态不变否则变为 不选择状态  
        /// </summary>  
        /// <param name="node"></param>  
        private void ValidParentNodeIsCanleSel(DevExpress.XtraTreeList.Nodes.TreeListNode node)
        {
            bool isSel = false;
            if (node.ParentNode != null)
            {
                if (node.ParentNode.CheckState == CheckState.Indeterminate)
                {
                    //如果父节点的 状态为 半选 状态 这 根据父节点 判断子节点是否打钩  
                    isSel = ValidIsHasCheckChildNode(node.ParentNode);
                    if (isSel == false)
                    {
                        //如果所有的 子节点 都没有 “选中”那么 父节点的状态 变为 非选中状态  
                        node.ParentNode.CheckState = CheckState.Unchecked;
                    }
                }
                this.ValidParentNodeIsCanleSel(node.ParentNode);
            }
        }

        /// <summary>  
        /// 判断该节点下是否有节点被选中，如果有返回true  
        /// </summary>  
        /// <param name="node"></param>  
        /// <returns></returns>  
        private bool ValidIsHasCheckChildNode(DevExpress.XtraTreeList.Nodes.TreeListNode node)
        {
            bool isCheck = false;
            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode cnode in node.Nodes)
            {
                if (cnode != null)
                {
                    if (cnode.CheckState == CheckState.Checked)
                    {
                        isCheck = true;
                        return isCheck;
                    }
                }
                if (cnode.HasChildren)
                {
                    isCheck = this.ValidIsHasCheckChildNode(cnode);
                    if (isCheck == true)
                    {
                        return isCheck;
                    }
                }
            }
            return isCheck;
        }
        /// <summary>  
        /// 节点全选  
        /// </summary>  
        /// <param name="node"></param>  
        /// <returns></returns>  
        private bool ValidIsCheckAllChildNode(DevExpress.XtraTreeList.Nodes.TreeListNode node)
        {
            bool isCheck = true;
            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode cnode in node.Nodes)
            {
                if (cnode != null)
                {
                    if (cnode.CheckState == CheckState.Unchecked)
                    {
                        isCheck = false;
                        return isCheck;
                    }
                }
                if (cnode.HasChildren)
                {
                    isCheck = this.ValidIsCheckAllChildNode(cnode);
                    if (isCheck == false)
                    {
                        return isCheck;
                    }
                }
            }
            return isCheck;
        }

        #endregion

        #region  树形 获取全部子节点
        private void GetChildNodes(TreeListNode parentNode, List<TreeListNode> list)
        {
            if (parentNode == null)
            {
                return;
            }
            if (parentNode.Nodes.Count > 0)
            {
                foreach (TreeListNode node in parentNode.Nodes)
                {
                    list.Add(node);
                    if (node.Nodes.Count > 0)
                    {
                        GetChildNodes(node, list);
                    }
                }
            }
        }
        #endregion

        #region 树形 选择子节点时触发
        /// <summary>  
        /// 选择子节点时触发  
        /// </summary>  
        /// <param name="node"></param>  
        /// <param name="check"></param>  
        private void SetCheckedChildNodes(TreeListNode node, CheckState check)
        {
            foreach (TreeListNode tn in node.Nodes)
            {
                tn.CheckState = check;
                if (tn.HasChildren)
                {
                    SetCheckedChildNodes(tn, check);
                }
            }
        }
        #endregion

        #region  树形 选择父节点时触发
        /// <summary>  
        /// 选择父节点时触发  
        /// </summary>  
        /// <param name="node"></param>  
        /// <param name="check"></param>  
        private void SetCheckedParentNodes(TreeListNode node, CheckState check)
        {
            if (node.ParentNode != null)
            {
                bool b = false;
                CheckState state;
                foreach (TreeListNode tln in node.ParentNode.Nodes)
                {
                    state = (CheckState)tln.CheckState;
                    if (!check.Equals(state))
                    {
                        b = !b;
                        break;
                    }
                }
                node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
                SetCheckedParentNodes(node.ParentNode, check);
            }
        }
        #endregion

        #region 树形 判断此节点下的所有孩子节点是否选中
        /// <summary>  
        /// 判断此节点下的所有孩子节点是否选中  
        /// </summary>  
        /// <param name="node"></param>  
        /// <returns></returns>  
        private Boolean IsChildsChecked(TreeListNode node)
        {
            foreach (TreeListNode tln in node.ParentNode.Nodes)
            {
                if (tln.CheckState == CheckState.Unchecked)
                {
                    return false;
                }
                if (tln.HasChildren)
                {
                    IsChildsChecked(tln);
                }
            }
            return true;
        }
        #endregion

        /// <summary>
        ///同步父子节点勾选状态
        ///说明
        ///在AfterCheckNode事件中使用代码
        ///eg:e.Node.SyncNodeCheckState(e.Node.CheckState);
        /// </summary>
        /// <param name="node">需要同步的节点</param>
        /// <param name="check">节点当前勾选状态</param>
        //public  void SyncNodeCheckState(this TreeListNode node, CheckState check) { SyncNodeCheckState_Child(node, check); SyncNodeCheckState_Parent(node, check); }

        //private  void SyncNodeCheckState_Child(TreeListNode node, CheckState check)
        //{
        //    //if (node != null)
        //    //{
        //    //    DownRecursiveNode(n => n.CheckState = check);
        //    //}
        //}
        private void SyncNodeCheckState_Parent(TreeListNode node, CheckState check)
        {
            if (node.ParentNode != null)
            {
                bool _cked = false;
                CheckState _ckState;
                foreach (TreeListNode cn in node.ParentNode.Nodes)
                {
                    _ckState = cn.CheckState;
                    if (check != _ckState)
                    {
                        _cked = !_cked;
                        break;
                    }
                }
                node.ParentNode.CheckState = _cked ? CheckState.Indeterminate : check;
                SyncNodeCheckState_Parent(node.ParentNode, check);
            }
        }

        private void btnBatch_Click(object sender, EventArgs e)
        {

        }

        private void chart_Day_Click(object sender, EventArgs e)
        {

        }

        private void sbtnView_Click(object sender, EventArgs e)
        {
            DoView(null);
        }

        private void cmbProductLine_SelectedIndexChanged(object sender, EventArgs e)
        {
            string productType = "";
            switch (cmbProductLine.Text)
            {
                case "MCG": productType="M"; break;
                case "Laminate": productType = "D"; break;

                case "Panel": productType = "P"; break;
                case "Seating": productType = "S"; break;
            }
            string sql = @"select distinct(PROCESS_NAME) [工作中心],PROCESS_CODE as [工作中心代码] from IE_WorkCenter_Definition where PROCESS_CODE like '"+ productType + "%' order by PROCESS_CODE desc";

            DataTable dtproduct = Lamex.Base.BaseBuildSql.GetDataTableBySql(sql);
           cmbFactoryCenter.Properties.DisplayMember = "工作中心";
            cmbFactoryCenter.Properties.ValueMember = "工作中心代码";
            cmbFactoryCenter.Properties.DataSource = dtproduct;
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            Lamex.Common.ExecelHelper.GridViewToExcel(gridView1);
        }

        public override void DoExport(IButtonInfo sender)
        {
            btnExport_Click(null, null);
        }
    }
}
